import Vue from 'vue'
import VueRouter from 'vue-router'
import top from "@/components/userCommon/top";
import borrow from "@/components/user/borrow";
import person from "@/components/user/person";
import recommend from "@/components/user/recommend";
import search from "@/components/user/search";
import share from "@/components/user/share";
import tell from "@/components/user/tell";
import main from "@/components/user/main";
import bottom from "@/components/userCommon/bottom";
import myBorrow from "@/components/user/Person/myBorrow";
import myCost from "@/components/user/Person/myCost";
import myShare from "@/components/user/Person/myShare";
import mySetting from "@/components/user/Person/mySetting";
import register from '@/components/register&login/register';
import login from "@/components/register&login/login.vue";
import forget from "@/components/register&login/forget.vue"
import book from "@/components/admin/books.vue"
import user from "@/components/admin/users.vue"
import announcement from "@/components/admin/announcements.vue"
import chart from "@/components/admin/chart.vue"
import edit from "@/components/admin/edit.vue"
import chat from "@/components/admin/chat.vue"
Vue.use(VueRouter)

const routes = [
  {
    path: '/top',
    name: 'top',
    component: top,
    children: [
      {
        path: '/main',
        name:'main',
        component: main
      },
      {
        path: '/borrow',
        name:'borrow',
        component: borrow
      },
      {
        path: '/person',
        name:'person',
        component: person,
        children:[
          {
            path: '/myBorrow',
            name:'myBorrow',
            component: myBorrow
          },
          {
            path: '/myShare',
            name:'myShare',
            component: myShare
          },
          {
            path: '/myCost',
            name:'myCost',
            component: myCost
          },
          {
            path: '/mySetting',
            name:'mySetting',
            component: mySetting
          },
        ]
      },
      {
        path: '/recommend',
        name:'recommend',
        component: recommend
      },
      {
        path: '/search',
        name:'search',
        component: search
      },
      {
        path: '/share',
        name:'share',
        component: share
      },
      {
        path: '/tell',
        name:'tell',
        component: tell
      },
    ]

  },
  {
    path: '/register',
    component: register
  },
  {
    path: '/',
    component: login
  },
  {
    path: '/forget',
    component: forget
  },
  {
    path: '/admin/book',
    component: book
  },
  {
    path: '/admin/user',
    component: user
  },
  {
    path: '/admin/announcement',
    component: announcement
  },
  {
    path: '/admin/chart',
    component: chart
  },
  {
    path: '/admin/edit',
    component: edit
  },
  {
    path: '/admin/chat',
    component: chat
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const originalReplace = VueRouter.prototype.place;
VueRouter.prototype.place = function place(location) {
  return originalReplace.call(this, location).catch(err => err)
}
export default router

